package lol.oxguy3.android.notificationz;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class NotificationzActivity extends Activity {
	
	private static final int NOTIFY_ME_ID = 1337;
	private Timer timer = new Timer();
	private int count = 0;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button btn1 = (Button) findViewById(R.id.button1);
        Button btn2 = (Button) findViewById(R.id.button2);
        
        btn1.setOnClickListener(new View.OnClickListener(){
        	
        	public void onClick(View v) {
        		
				TimerTask task = new TimerTask(){
					@Override public void run() { notifyMe(); } };
				timer.schedule(task, 500);
				
			}
        	
        });
        
        
        btn2.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
				nm.cancel(NOTIFY_ME_ID);
			}
		});
        
    }
    
    
    public void notifyMe() {
    	final NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    	Notification note = new Notification(R.drawable.poo, "THIS IS A NOTIFICATION!", System.currentTimeMillis());
    	PendingIntent pint = PendingIntent.getActivity(this, 0, new Intent(this, NotificationzActivity.class), 0);
    	note.setLatestEventInfo(this, "Notification Title", "This doth be a notification", pint);
    	note.number = ++count;
    	note.defaults |= Notification.DEFAULT_SOUND;
    	//note.defaults |= Notification.DEFAULT_VIBRATE;
    	note.defaults |= Notification.DEFAULT_LIGHTS;
    	nm.notify(NOTIFY_ME_ID, note);
    }
    
}